package com.iwdnb.gkgz.application.analysis;

import java.util.List;

import com.iwdnb.gkgz.common.model.dto.StockDayData;
import com.iwdnb.gkgz.common.model.dto.StrategyTradeDTO;
import com.iwdnb.gkgz.common.quota.BollingerBands;
import com.iwdnb.gkgz.common.quota.MovingAverage;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class StockAnalysisContext {
    @Autowired
    private List<StockAnalysisService> stockAnalysisServices;

    public void analysisStock(String code, List<StockDayData> stockDayDataList, StrategyTradeDTO strategyTradeDTO,
        AnalysisParam param) {
        //初始化
        init(code, stockDayDataList);
        //执行解析
        for (StockAnalysisService stockAnalysisService : stockAnalysisServices) {
            stockAnalysisService.analysis(code, stockDayDataList, strategyTradeDTO, param);
        }
    }

    private void init(String code, List<StockDayData> stockDayDataList) {
        int twentyPeriod = 20;
        int thirtyPeriod = 30;
        int sixtyPeriod = 60;
        MovingAverage.calculateEMA(stockDayDataList, twentyPeriod);
        MovingAverage.calculateEMA(stockDayDataList, thirtyPeriod);
        MovingAverage.calculateEMA(stockDayDataList, sixtyPeriod);
        BollingerBands.calculateBollingerBands(stockDayDataList);
    }

    @Data
    public static class AnalysisParam {

        private int buyDownLimitCount = 0;

        private int downLimitCount = 0;

        private int downLimitHoldDayCount = 0;

        private int noDownLimitCount = 0;

        private int totalCount;
    }
}
